<template>
  <transition name='slide' appear>
  <music-list :title='title' :bg-image='bgImage' :songs='songs'></music-list>
  </transition>
</template>

<script>
  import { getSingerDetaild } from 'api'
  import { mapGetters } from 'vuex'
  import { createSong } from 'common/js/song'
  import MusicList from 'components/music-list/music-list'

  export default {
    data() {
      return {
        songs: []
      }
    },
    computed: {
      title() {
        return this.singer.name
      },
      bgImage() {
        return this.singer.avatar
      },
      ...mapGetters([
        'singer'
      ])
    },
    created() {
      this._getDetail()
    },
    mounted() {
      this.$nextTick(() => {

      })
    },
    methods: {
      _getDetail() {
        if (!this.singer.id) {
          this.$router.push('/singer')
          return
        }
        let params = { id: this.singer.id }
        getSingerDetaild(params).then(res => {
          this.songs = this._normalizeSong(res.data.hotSongs)
        })
      },
      _normalizeSong(list) {
        let ret = []
        list.forEach((item) => {
          if (item.id) {
            let song = createSong(item)
            ret.push(song)
          }
        })
        return ret
      }
    },
    components: {
      MusicList
    }
  }
</script>

<style scoped lang="stylus" rel="stylesheet/stylus">
  @import "~common/stylus/variable"
  .slide-enter-active, .slide-leave-active
    transition: all 0.3s
  .slide-enter, .slide-leave-to
    transform: translate3d(100%, 0, 0)
</style>
